﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Common.Interfaces;
using PCSWpfData.Extensions;
using System.Data.Entity;
using Common.Helpers;

namespace PCSWpfData
{
    public class SelectionCriteria :IRepository 
    {
        public ICollection<Common.Instrument> GetSelectionCriteria()
        {
            using (var Context = new CombinedDbContext())
            {

                var instr = Context.CompleteInstruments().ToList();

                return instr;
            }
        }

        public List<Common.Instrument> GetInstruments()
        {
            using (var Context = new CombinedDbContext())
            {
                return Context.CompleteInstruments().ToList();
            }

        }

        public async Task<ICollection<Common.Instrument>> GetSelectionCriteriaAsync(RangeEnabledObservableCollection<Common.Instrument> instrumentList)
        {
            using (var Context = new CombinedDbContext())
            {
                
                var instr = await (from p in Context.CompleteInstruments()
                                  select p).ToListAsync();
                //throw new Exception("timeout"); throw an exception to see the error appear on the guid
                instrumentList.InsertRange(instr.ToList());
                return instr;
            }
        }

        public ICollection<Common.Price> GetPrices(Common.PriceSeries priceSeries)
        {
            throw new NotImplementedException();
        }

        public ICollection<Common.Dividend> GetDividends(Common.PriceSeries priceSeries)
        {
            throw new NotImplementedException();
        }


    }

}
